package com.speedricemanager.activity.home.registerauditlist;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.ImageView;

import com.speedricemanager.R;
import com.speedricemanager.activity.home.fragmenadapter.FragmentAdapter;
import com.speedricemanager.activity.home.registeframent.RegisterSeek;
import com.speedricemanager.activity.home.registeframent.RegisterauditFrament;
import com.speedricemanager.other.base.BaseAty;
import com.vondear.rxtools.view.RxTitle;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 李征 on 2017/12/17.
 */

public class RegisterAuditLIst extends BaseAty {
    @InjectView(R.id.rx_title)
    RxTitle rxTitle;

    @InjectView(R.id.tabLayout)
    TabLayout tabLayout;
    @InjectView(R.id.viewpager)
    ViewPager viewpager;
    @InjectView(R.id.send_add)
    ImageView sendAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.registerauditlist);
        ButterKnife.inject(this);
        setTitle(rxTitle);
        settitle();
    }

    private void settitle() {
        ArrayList<String> arrtitle = new ArrayList<>();
        final ArrayList<Fragment> arrfrag = new ArrayList<>();
        arrtitle.add("待审核");
        arrtitle.add("已通过");
        arrtitle.add("已拒绝");
        for (int i = 0; i < arrtitle.size(); i++) {
            tabLayout.addTab(tabLayout.newTab().setText(arrtitle.get(i)));
            arrfrag.add(new RegisterauditFrament());
        }
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), arrfrag, arrtitle);
        //给ViewPager设置适配器
        viewpager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        tabLayout.setupWithViewPager(viewpager);
        //给TabLayout设置适配器
        tabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                String stats = null;
                switch (position) {
                    case 0:
                        stats = "1";
                        break;
                    case 1:
                        stats = "2,4,5,6,7";
                        break;
                    case 2:
                        stats = "3";
                        break;
                }
                ((RegisterauditFrament) arrfrag.get(position)).setOnClick(stats, position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });

    }

    @OnClick(R.id.send_add)
    public void onViewClicked() {

startActivity(new Intent(this, RegisterSeek.class));


    }

    public interface OnCallAoom {
        void setOnClick(String statics, int tag);

    }


}
